<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
header("Access-Control-Allow-Origin: *");
class Test extends MY_Controller {

	public function __construct(){
		
		parent::__construct();
		
		$this->load->model('msg_m');
	}
	public function index()
	{
		
	}
	
	public function get()
	{
		$accountID = $this->input->post('accountID');
		$filter = array(
				'accountID' => $accountID,
				'status' => 0,
				'order' => 'DESC',
				'sort' => 'startTime');
		$arrMsg = $this->msg_m->getMsg($filter,0,1);
		
		$data = array(
				'status' => 1);
		foreach($arrMsg as $k =>$msg){
			$this->msg_m->setMsg($msg['id'],$data);
		}
		
	  
	   
	   if (!empty($arrMsg)){
	   	$this->data['status'] = true;
	   	$this->data['msg']    = $arrMsg[0]['title'];
	   }else{
	   	$this->data['status'] = false;
	   	  $this->data['msg'] = null;
	   }
	   
	   echo json_encode($this->data);
		
		
	}
	
	public function add()
	{
		$title           = $this->input->post('msg');
		
		echo $title;
		$accountID = $this->input->post('accountID');
		$toAdd = array(
				'accountID' => $accountID,
				'title' => $title,
				'content' => null,
				'total' => 1,
				'startTime' => date('Y-m-d H:i:s',time()),
				'status' => 0,
		);
		$msgID = $this->msg_m->addMsg($toAdd);
		
		$this->data['status'] = true;
		$this->data['msg']    = '成功了';
		
		echo json_encode($this->data);
		
	}
}

